
// 101.对称二叉树
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    bool isSymmetric(TreeNode* root) {
        // 使用递归来完成

        function<bool(TreeNode* , TreeNode*)> check = [&](TreeNode* pos1 , TreeNode * pos2)->bool
        {
            if(pos1 == nullptr && pos2 == nullptr) return true;
            if(pos1 == nullptr || pos2 == nullptr || pos1->val != pos2->val) return false;
            return check(pos1->left , pos2->right) && check(pos1->right , pos2->left);
        };
        return check(root->left , root->right);
    }
};